const TokenKey = 'token';

export const setLocalStorage = locals => {
    if (Array.isArray(locals)) {
        locals.forEach(item => {
            const key = Object.keys(item)[0];
            uni.setStorage({
                key,
                data: item[key]
            });
        });
    } else {
        Object.keys(locals).map(key => {
            const value = locals[key];
            uni.setStorage({
                key,
                data: value
            });
        });
    }
};

export const getLocalStorage = key => {
    return uni.getStorageSync(key);
};

export function getToken() {
    return getLocalStorage(TokenKey);
}

export function setToken(token) {
    return setLocalStorage({ [TokenKey]: token });
}

export function removeToken() {
    return localStorage.removeItem(TokenKey);
}

export function getAppId() {
    return getLocalStorage('appId');
}

export function setAppId(appId) {
    return setLocalStorage({ appId });
}

